package com.starnet.studentmanagement.controller;


import com.starnet.studentmanagement.entity.Courses;
import com.starnet.studentmanagement.service.CoursesService;
import com.starnet.studentmanagement.vo.PageResult;
import com.starnet.studentmanagement.vo.Result;
import com.starnet.studentmanagement.vo.param.PageParams;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author sangeng
 * @since 2022-03-26
 */
@Api(value = "课程管理")
@RestController
@RequestMapping("/courses")
public class CoursesController {
    @Autowired
    CoursesService coursesService;

    @ApiOperation(value = "课程查询")
    @GetMapping()
    public PageResult listPage(@RequestParam(value = "cname",required = false)String cname,@RequestParam(value = "page")Integer page,@RequestParam(value = "pageSize",required = false)Integer pageSize) {
        return coursesService.listPage(cname,page,pageSize);
    }


    @ApiOperation(value = "新增课程")
    @PostMapping
    public Result addNewCourse(@RequestBody @Valid Courses course) {
        return coursesService.addNewCourse(course);
    }

    @ApiOperation(value = "修改课程")
    @PutMapping
    public Result updateCourse(@RequestBody @Valid Courses course) {
        return coursesService.updateCourse(course);
    }

    @ApiOperation(value = "删除课程")
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable("id") int id) {
        return coursesService.deleteById(id);
    }


}
